package com.leetcode;

/**
 * TODO
 *
 * @author lefly
 * @version 1.0
 * @classname No53
 * @description 最大子序和
 * @date 2021/3/2 下午5:07
 */
public class No53 {
    public static void main(String[] args) {
        int[] nums = {-2,1,-3,4,-1,2,1,-5,4};
        int res = maxSubArray(nums);
        System.out.println(res);
    }

    public static int maxSubArray(int[] nums){
        int len = nums.length;
        int imax = nums[0];
        int max = imax;
        for (int i = 1; i < len; i++) {
            int data = nums[i];
            imax = imax > 0 ? imax + data : data;
            max = Math.max(imax,max);
        }
        return max;
    }

}
